<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui">
    <ui:define name="content">
        <h:panelGroup >
            <h:form id="form"  >
                <p:growl />
                <p:panel header="Manage Package Item Fees" >
                    <p:panelGrid columns="1" >
                        <p:panelGrid columns="2" >
                            <h:outputLabel value="Select Package" />
                            <p:autoComplete widgetVar="aIx" id="acIx" 
                                            converter="conMedical" 
                                            forceSelection="true" 
                                            value="#{medicalPackageItemFeeController.currentPackege}"
                                            completeMethod="#{medicalPackageNameController.completePack}"
                                            var="ix" itemLabel="#{ix.name}" itemValue="#{ix}" size="30" 
                                            style="width: 400px;">
                                <p:ajax event="itemSelect" process="@this" update="cur gpVeda dtbFee" ></p:ajax>
                            </p:autoComplete>
                        </p:panelGrid>

                        <h:selectOneListbox id="cur" value="#{medicalPackageItemFeeController.currentIx}">
                            <f:selectItems value="#{medicalPackageItemFeeController.items}" var="pk" itemLabel="#{pk.item.name}" itemValue="#{pk.item}"/>
                            <f:ajax execute="@this" render="gpVeda dtbFee"/>
                        </h:selectOneListbox>

                        <h:panelGrid id ="gpVeda" columns="2" styleClass="alignTop" >
                            <p:panel   >                                    
                                <f:facet name="header" >
                                    <h:outputLabel value="Charge Detail" ></h:outputLabel>
                                    <h:outputText style="float:right;" id="lblTotal" value="Total : #{medicalPackageItemFeeController.total}"/>
                                </f:facet>
                                <h:panelGrid columns="2">
                                    <h:outputText value="Fee Name"/>
                                    <h:inputText autocomplete="off" id="txtFeeName" value="#{medicalPackageItemFeeController.currentFee.name}"/>
                                    <h:outputText value="Fee Type"/>
                                    <h:selectOneListbox id="cmbFeeType" size="1" value="#{medicalPackageItemFeeController.currentFee.feeType}" >
                                        <f:selectItem itemLabel="Please select the type"/>
                                        <f:selectItem itemLabel="Staff Fee" itemValue="Staff" />
                                        <f:selectItem itemLabel="Hospital Fee" itemValue="OwnInstitution" />
                                        <f:selectItem itemLabel="Outside Fee" itemValue="OtherInstitution" />
                                    </h:selectOneListbox>

                                    <h:outputText value="Speciality"/>
                                    <p:autoComplete converter="specilityCon" forceSelection="true" id="cmbSpe" value="#{medicalPackageItemFeeController.currentFee.speciality}" completeMethod="#{specialityController.completeSpeciality}" var="sp" itemLabel="#{sp.name}" itemValue="#{sp}" size="30"  style="width: 400px;">
                                        <f:ajax execute="cmbSpe" render="cmbDoc" event="select"/>
                                    </p:autoComplete>


                                    <h:outputText value="Staff"/>
                                    <p:autoComplete converter="stfcon" forceSelection="true" id="cmbDoc" value="#{medicalPackageItemFeeController.currentFee.staff}" completeMethod="#{medicalPackageItemFeeController.completeStaff}" var="st" itemLabel="#{st.person.nameWithTitle}" itemValue="#{st}" size="30"  style="width: 400px;">
                                        <f:ajax execute="cmbSpe" event="keypress"/>
                                    </p:autoComplete>
                                    <h:outputText value="Institution"/>
                                    <h:selectOneListbox id="cmbInstitution" size="1" value="#{medicalPackageItemFeeController.currentFee.institution}" >
                                        <f:selectItem itemLabel="Please select an Institution"/>
                                        <f:selectItems value="#{institutionController.companies}" var="ins" itemLabel="#{ins.name}" itemValue="#{ins}" />
                                        <f:ajax execute="cmbInstitution" render="cmbDepartment" event="change"/> 
                                    </h:selectOneListbox>
                                    <h:outputText value="Department"/>
                                    <h:selectOneListbox id="cmbDepartment" size="1" value="#{medicalPackageItemFeeController.currentFee.department}" >
                                        <f:selectItem itemLabel="Please select an Institution"/>
                                        <f:selectItems value="#{medicalPackageItemFeeController.institutionDepatrments}" var="dep" itemLabel="#{dep.name}" itemValue="#{dep}" />
                                    </h:selectOneListbox>
                                    <h:outputText value="Fee"/>
                                    <h:inputText autocomplete="off" id="txtFee" value="#{medicalPackageItemFeeController.currentFee.fee}"/>
                                    <h:outputText value=""/>
                                    <h:commandButton id="btnAddTo" value="Add" action="#{medicalPackageItemFeeController.saveCharge}" styleClass="buttons">
                                        <f:ajax render="dtbFee gpVeda" execute="gpVeda :#{p:component('cur')}"  />
                                    </h:commandButton>
                                     <p:defaultCommand target="btnAddTo"/>
                                </h:panelGrid>

                                <p:dataTable id="dtbFee" rowIndexVar="rowIndex" value="#{medicalPackageItemFeeController.charges}" var="bi" >
                                    <p:column headerText="Fee Name">
                                        <h:outputLabel value="#{bi.name}"/>
                                    </p:column>
                                    <p:column headerText="Speciality">
                                        <h:outputLabel value="#{bi.speciality.name}"/>
                                    </p:column>
                                    <p:column headerText="Department">
                                        <h:outputLabel value="#{bi.department.name}"/>
                                    </p:column>
                                    <p:column headerText="Staff">
                                        <h:outputLabel value="#{bi.staff.person.nameWithTitle}"/>
                                    </p:column>
                                    <p:column headerText="Fee">
                                        <h:outputLabel value="#{bi.fee}"/>
                                    </p:column>
                                    <p:column headerText="Remove">
                                        <h:commandButton id="remove" value="Remove" action="#{medicalPackageItemFeeController.removeFee}" >
                                            <f:setPropertyActionListener value="#{bi}" target="#{medicalPackageItemFeeController.removedMedicalPackageFee}"/>
                                            <p:ajax update=":#{p:component('lblTotal')} dtbFee" process="remove dtbFee" />
                                        </h:commandButton>
                                    </p:column>
                                </p:dataTable>

                            </p:panel>

                        </h:panelGrid>

                    </p:panelGrid>





                </p:panel>
            </h:form>

        </h:panelGroup>

    </ui:define>

</ui:composition>
